﻿using System;
using System.Collections;
using System.Data;
using CE.Database;

/// <summary>
/// Summary description for CompareBenefitsDB
/// </summary>
/// 
namespace CE.Provider
{
    public class CompareBenefitsDB
    {
        public CompareBenefitsDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Int64 Insert(CompareBenefits comparebenefits)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocPACompareBenefitsInsertUpdateSingleItem";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@PAInsId", comparebenefits.PAInsId);
            _sPara.Add("@PACompanyId", comparebenefits.PACompanyId);
            _sPara.Add("@PlanName", comparebenefits.PlanName);
            _sPara.Add("@BenefitName", comparebenefits.BenefitName);
            _sPara.Add("@PolicyType", comparebenefits.PolicyType);
            _sPara.Add("@AnnualPremiumInd", comparebenefits.AnnualPremiumInd);
            _sPara.Add("@AnnualPremiumSpouse", comparebenefits.AnnualPremiumSpouse);
            _sPara.Add("@AnnualPremiumChild", comparebenefits.AnnualPremiumChild);
            _sPara.Add("@TotalAnnualPremium", comparebenefits.TotalAnnualPremium);
            _sPara.Add("@DeathAdult", comparebenefits.DeathAdult);
            //_sPara.Add("@DeathChild", comparebenefits.DeathChild);
            _sPara.Add("@TPDAdult", comparebenefits.TPDAdult);
            //_sPara.Add("@TPDChild", comparebenefits.TPDChild);
            _sPara.Add("@IsMedicalExpA", comparebenefits.IsMedicalExpA);
            _sPara.Add("@MedExpAdult", comparebenefits.MedExpAdult);
            //_sPara.Add("@IsMedicalExpC", comparebenefits.IsMedicalExpC);
            //_sPara.Add("@MedExpChild", comparebenefits.MedExpChild);
            _sPara.Add("@IsDentalTreatment", comparebenefits.IsDentalTreatment);                //New 13 Dec 2010 by Sakthi
            _sPara.Add("@DentalTreatment", comparebenefits.DentalTreatment);                    //New 13 Dec 2010 by Sakthi
            _sPara.Add("@IsChineseMedicalExpenses", comparebenefits.IsChineseMedicalExpenses);  //New 13 Dec 2010 by Sakthi
            _sPara.Add("@ChineseMedicalExpenses", comparebenefits.ChineseMedicalExpenses);      //New 13 Dec 2010 by Sakthi
            _sPara.Add("@IsHaspitalCPDA", comparebenefits.IsHaspitalCPDA);
            _sPara.Add("@HCPDAdult", comparebenefits.HCPDAdult);
            //_sPara.Add("@IsHaspitalCPDC", comparebenefits.IsHaspitalCPDC);
            //_sPara.Add("@HCPDChild", comparebenefits.HCPDChild);
            _sPara.Add("@IsRecuperation", comparebenefits.IsRecuperation);
            _sPara.Add("@RecupBenefit", comparebenefits.RecupBenefit);
            _sPara.Add("@IsBereavement", comparebenefits.IsBereavement);
            _sPara.Add("@BereaveRelief", comparebenefits.BereaveRelief);
            _sPara.Add("@DoubleIndemnity", comparebenefits.DoubleIndemnity);
            _sPara.Add("@IsTempTotDisPW", comparebenefits.IsTempTotDisPW);
            _sPara.Add("@TempTDPW", comparebenefits.TempTDPW);
            _sPara.Add("@IsTempPartDisPW", comparebenefits.IsTempPartDisPW);
            _sPara.Add("@TempPDPW", comparebenefits.TempPDPW);
            _sPara.Add("@IsCompassionateCash", comparebenefits.IsCompassionateCash);    //New 13 Dec 2010 by Sakthi
            _sPara.Add("@CompassionateCash", comparebenefits.CompassionateCash);        //New 13 Dec 2010 by Sakthi
            _sPara.Add("@IsKidnapBenefit", comparebenefits.IsKidnapBenefit);            //New 13 Dec 2010 by Sakthi
            _sPara.Add("@KidnapBenefit", comparebenefits.KidnapBenefit);                //New 13 Dec 2010 by Sakthi
            _sPara.Add("@Terrorism", comparebenefits.Terrorism);
            _sPara.Add("@Class1", comparebenefits.Class1);
            _sPara.Add("@Class2", comparebenefits.Class2);
            _sPara.Add("@Class3", comparebenefits.Class3);
            _sPara.Add("@Class4", comparebenefits.Class4);
            _sPara.Add("@AgeLimitFrom", comparebenefits.AgeLimitFrom);
            _sPara.Add("@AgeLimitTo", comparebenefits.AgeLimitTo);
            _sPara.Add("@Status", comparebenefits.Status);
            _sPara.Add("@RefCEUserId", comparebenefits.RefCEUserId);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public CompareBenefits GetCompareBenefits(Int64 PACompanyId, Int64 PAInsId)
        {
            CompareBenefits _comparebenefits = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocPACompareBenefitsSelectSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@PACompanyId", PACompanyId);
            _spara.Add("@PAInsId", PAInsId);

            DataTable _dt = _db.GetDataTableBySP(_spName, _spara);
            if (_dt != null)
            {
                _comparebenefits = new CompareBenefits();
                _comparebenefits = FillDataRecord(_dt);
            }
            return _comparebenefits;
        }

        private CompareBenefits FillDataRecord(DataTable myDataTable)
        {
            CompareBenefits myCompareBenefits = new CompareBenefits();
            myCompareBenefits.PAInsId = Convert.ToInt64(myDataTable.Rows[0]["PAInsId"].ToString());
            myCompareBenefits.PACompanyId = Convert.ToInt64(myDataTable.Rows[0]["PACompanyId"].ToString());
            myCompareBenefits.PlanName = myDataTable.Rows[0]["PlanName"].ToString();
            myCompareBenefits.BenefitName = myDataTable.Rows[0]["BenefitName"].ToString();
            myCompareBenefits.PolicyType = myDataTable.Rows[0]["PolicyType"].ToString();
            myCompareBenefits.AnnualPremiumInd = Convert.ToSingle(myDataTable.Rows[0]["AnnualPremiumInd"].ToString());
            myCompareBenefits.AnnualPremiumSpouse = Convert.ToSingle(myDataTable.Rows[0]["AnnualPremiumSpouse"].ToString());
            myCompareBenefits.AnnualPremiumChild = Convert.ToSingle(myDataTable.Rows[0]["AnnualPremiumChild"].ToString());
            myCompareBenefits.TotalAnnualPremium = Convert.ToSingle(myDataTable.Rows[0]["TotalAnnualPremium"].ToString());
            myCompareBenefits.AnnualPremiumWithGST = Convert.ToSingle(myDataTable.Rows[0]["AnnualPremiumWithGST"].ToString());
            myCompareBenefits.DeathAdult = Convert.ToSingle(myDataTable.Rows[0]["DeathAdult"].ToString());
            //myCompareBenefits.DeathChild = Convert.ToSingle(myDataTable.Rows[0]["DeathChild"].ToString());
            myCompareBenefits.TPDAdult = Convert.ToSingle(myDataTable.Rows[0]["TPDAdult"].ToString());
            //myCompareBenefits.TPDChild = Convert.ToSingle(myDataTable.Rows[0]["TPDChild"].ToString());
            myCompareBenefits.IsMedicalExpA = Convert.ToBoolean(myDataTable.Rows[0]["IsMedicalExpA"].ToString());
            myCompareBenefits.MedExpAdult = Convert.ToSingle(myDataTable.Rows[0]["MedExpAdult"].ToString());
            //myCompareBenefits.IsMedicalExpC = Convert.ToBoolean(myDataTable.Rows[0]["IsMedicalExpC"].ToString());
            //myCompareBenefits.MedExpChild = Convert.ToSingle(myDataTable.Rows[0]["MedExpChild"].ToString());
            myCompareBenefits.IsDentalTreatment = Convert.ToBoolean(myDataTable.Rows[0]["IsDentalTreatment"].ToString());               //New 13 Dec 2010 by Sakthi
            myCompareBenefits.DentalTreatment = Convert.ToSingle(myDataTable.Rows[0]["DentalTreatment"].ToString());                    //New 13 Dec 2010 by Sakthi
            myCompareBenefits.IsChineseMedicalExpenses = Convert.ToBoolean(myDataTable.Rows[0]["IsChineseMedicalExpenses"].ToString()); //New 13 Dec 2010 by Sakthi
            myCompareBenefits.ChineseMedicalExpenses = Convert.ToSingle(myDataTable.Rows[0]["ChineseMedicalExpenses"].ToString());      //New 13 Dec 2010 by Sakthi
            myCompareBenefits.IsHaspitalCPDA = Convert.ToBoolean(myDataTable.Rows[0]["IsHaspitalCPDA"].ToString());
            myCompareBenefits.HCPDAdult = Convert.ToSingle(myDataTable.Rows[0]["HCPDAdult"].ToString());
            //myCompareBenefits.IsHaspitalCPDC = Convert.ToBoolean(myDataTable.Rows[0]["IsHaspitalCPDC"].ToString());
            //myCompareBenefits.HCPDChild = Convert.ToSingle(myDataTable.Rows[0]["HCPDChild"].ToString());
            myCompareBenefits.IsRecuperation = Convert.ToBoolean(myDataTable.Rows[0]["IsRecuperation"].ToString());
            myCompareBenefits.RecupBenefit = Convert.ToSingle(myDataTable.Rows[0]["RecupBenefit"].ToString());
            myCompareBenefits.IsBereavement = Convert.ToBoolean(myDataTable.Rows[0]["IsBereavement"].ToString());
            myCompareBenefits.BereaveRelief = Convert.ToSingle(myDataTable.Rows[0]["BereaveRelief"].ToString());
            myCompareBenefits.DoubleIndemnity = Convert.ToBoolean(myDataTable.Rows[0]["DoubleIndemnity"].ToString());
            myCompareBenefits.IsTempTotDisPW = Convert.ToBoolean(myDataTable.Rows[0]["IsTempTotDisPW"].ToString());
            myCompareBenefits.TempTDPW = Convert.ToSingle(myDataTable.Rows[0]["TempTDPW"].ToString());
            myCompareBenefits.IsTempPartDisPW = Convert.ToBoolean(myDataTable.Rows[0]["IsTempPartDisPW"].ToString());
            myCompareBenefits.TempPDPW = Convert.ToSingle(myDataTable.Rows[0]["TempPDPW"].ToString());
            myCompareBenefits.IsCompassionateCash = Convert.ToBoolean(myDataTable.Rows[0]["IsCompassionateCash"].ToString());   //New 13 Dec 2010 by Sakthi
            myCompareBenefits.CompassionateCash = Convert.ToSingle(myDataTable.Rows[0]["CompassionateCash"].ToString());        //New 13 Dec 2010 by Sakthi
            myCompareBenefits.IsKidnapBenefit = Convert.ToBoolean(myDataTable.Rows[0]["IsKidnapBenefit"].ToString());           //New 13 Dec 2010 by Sakthi
            myCompareBenefits.KidnapBenefit = Convert.ToSingle(myDataTable.Rows[0]["KidnapBenefit"].ToString());                //New 13 Dec 2010 by Sakthi
            myCompareBenefits.Terrorism = Convert.ToBoolean(myDataTable.Rows[0]["Terrorism"].ToString());
            myCompareBenefits.Class1 = Convert.ToBoolean(myDataTable.Rows[0]["Class1"].ToString());
            myCompareBenefits.Class2 = Convert.ToBoolean(myDataTable.Rows[0]["Class2"].ToString());
            myCompareBenefits.Class3 = Convert.ToBoolean(myDataTable.Rows[0]["Class3"].ToString());
            myCompareBenefits.Class4 = Convert.ToBoolean(myDataTable.Rows[0]["Class4"].ToString());
            myCompareBenefits.AgeLimitFrom = Convert.ToInt32(myDataTable.Rows[0]["AgeLimitFrom"].ToString());
            myCompareBenefits.AgeLimitTo = Convert.ToInt32(myDataTable.Rows[0]["AgeLimitTo"].ToString());
            myCompareBenefits.Status = Convert.ToBoolean(myDataTable.Rows[0]["Status"].ToString());
            myCompareBenefits.RefCEUserId = Convert.ToInt64(myDataTable.Rows[0]["RefCEUserId"].ToString());
            return myCompareBenefits;
        }

        public DataTable GetCompareBenefitsList(Int64 PACompanyId, string PolicyType)
        {
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocPAInsuranceSelectItemList";

            SortedList _spara = new SortedList();
            _spara.Add("@PACompanyId", PACompanyId);
            _spara.Add("@PolicyType", PolicyType);

            DataTable _dt = _db.GetDataTableBySP(_spName, _spara);

            return _dt;

        }

        
        //public DataTable GetPlanNames(Int64 PACompanyId, Int64 RefCEUserId)
        public DataTable GetPlanNames(Int64 PACompanyId)
        {
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocPAPlanNamesSelectItemList";

            SortedList _spara = new SortedList();
            _spara.Add("@PACompanyId", PACompanyId);
            //_spara.Add("@RefCEUserId", RefCEUserId);

            DataTable _dt = _db.GetDataTableBySP(_spName, _spara);

            return _dt;
           
        }

        //public DataTable GetBenefitNames(Int64 PACompanyId, Int64 RefCEUserId)
        public DataTable GetBenefitNames(Int64 PACompanyId)
        {
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocPABenefitNamesSelectItemList";

            SortedList _spara = new SortedList();
            _spara.Add("@PACompanyId", PACompanyId);
            //_spara.Add("@RefCEUserId", RefCEUserId);

            DataTable _dt = _db.GetDataTableBySP(_spName, _spara);

            return _dt;

        }

        //public DataTable GetBenefitNames(Int64 PACompanyId, Int64 RefCEUserId, string PlanName)
        public DataTable GetBenefitNames(Int64 PACompanyId, string PlanName)
        {
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocPABenefitNamesSelectItemList";

            SortedList _spara = new SortedList();
            _spara.Add("@PACompanyId", PACompanyId);
            //_spara.Add("@RefCEUserId", RefCEUserId);
            _spara.Add("@PlanName", PlanName);

            DataTable _dt = _db.GetDataTableBySP(_spName, _spara);

            return _dt;

        }

        //public DataTable GetBenefitNames(Int64 PACompanyId, Int64 RefCEUserId, string PlanName, string PolicyType)
        public DataTable GetBenefitNames(Int64 PACompanyId, string PlanName, string PolicyType)
        {
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocPABenefitNamesSelectItemList";

            SortedList _spara = new SortedList();
            _spara.Add("@PACompanyId", PACompanyId);
            //_spara.Add("@RefCEUserId", RefCEUserId);
            _spara.Add("@PlanName", PlanName);
            _spara.Add("@PolicyType", PolicyType);

            DataTable _dt = _db.GetDataTableBySP(_spName, _spara);

            return _dt;

        }

    }
}